package com.base.commonlib.utils;

import android.content.Context;
import android.view.View;
import android.widget.TextView;

import com.bigkoo.pickerview.builder.TimePickerBuilder;
import com.bigkoo.pickerview.listener.OnTimeSelectListener;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by arvin on 2018/10/25.
 */

public class TimePickUtil {


    public static void pickDateTime(Context contex, final TextView tv)
    {
        final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        TimePickerBuilder timePickerBuilder = new TimePickerBuilder(contex, new OnTimeSelectListener() {
            @Override
            public void onTimeSelect(Date date, View v) {
                tv.setText(dateFormat.format(date));
            }
        }).setType(new boolean[]{true, true, true, true, true, true})
                .setTitleBgColor(0xff1ca1fe)
                .setSubmitColor(0xffffffff)
                .setCancelColor(0xffffffff);
        timePickerBuilder.build().show();

    }

    public static void pickDate(Context contex, final TextView tv)
    {
        final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        TimePickerBuilder timePickerBuilder = new TimePickerBuilder(contex, new OnTimeSelectListener() {
            @Override
            public void onTimeSelect(Date date, View v) {
                tv.setText(dateFormat.format(date));
            }
        }).setType(new boolean[]{true, true, true, false, false, false})
                .setTitleBgColor(0xff1ca1fe)
                .setSubmitColor(0xffffffff)
                .setCancelColor(0xffffffff);
        timePickerBuilder.build().show();

    }

    public static void pickTime(Context contex, final TextView tv)
    {
        final SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
        TimePickerBuilder timePickerBuilder = new TimePickerBuilder(contex, new OnTimeSelectListener() {
            @Override
            public void onTimeSelect(Date date, View v) {
                tv.setText(dateFormat.format(date));
            }
        }).setType(new boolean[]{false, false, false, true, true, true})
                .setTitleBgColor(0xff1ca1fe)
                .setSubmitColor(0xffffffff)
                .setCancelColor(0xffffffff);
        timePickerBuilder.build().show();

    }
}
